package GUI.gameWin;

import gamePlus.client.ClientRoundUnit;

import java.awt.Color;
import java.util.LinkedList;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import carddeck.Card;

public class UsedCardPanelPlus extends JPanel {
	private ClientRoundUnit roundUnit;
	public UsedCardPanelPlus(ClientRoundUnit roundUnit) {
		super();
		this.roundUnit = roundUnit;
		setBorder(new TitledBorder(roundUnit.usedCardDeck.getCardCount()+" kart"));
		((TitledBorder) getBorder()).setTitleColor(Color.WHITE);
		setBackground(new Color(0, 77, 0));
		setLayout(new CardHorizontalLayout(15));
		setVisible(true);
		setOpaque(true);
	}
	
	public void updateBorder() {
		int i = roundUnit.usedCardDeck.getCardCount();
		String kart = "kart";
		if(i==1)
			kart+="a";
		if((i%10==2||i%10==3||i%10==4)&&i%100!=12&&i%100!=13&&i%100!=14)
			kart+="y";
			
		((TitledBorder) getBorder()).setTitle(i + " " + kart);
	}
	
	public void refresh() {
		removeAll();
		LinkedList<Card> usedList = roundUnit.usedCardDeck.getCards();
		updateBorder();
		if(usedList.size()==0)
			return;
		int i;
		if(usedList.size()<5)
			i=0;
		else
			i=usedList.size()-5;
		for (; i<usedList.size()-1;i++) {
			Card theCard = usedList.get(i);
			CardButtonPlus theButton = new CardButtonPlus(null, roundUnit, theCard, false, true);
			add(theButton);
		}
		Card theCard = usedList.getLast();
		CardButtonPlus theButton = new CardButtonPlus(null, roundUnit, theCard, true, true);
		add(theButton);
		revalidate();
		repaint();
	}
}
